package cmd

import (
	"log"

	"192.168.1.75/timer-schedule/config"
	"github.com/spf13/cobra"
	"github.com/spf13/viper"
)

func init() {
	rootCmd.AddCommand(versionCmd)
}

var versionCmd = &cobra.Command{
	Use:   "self-check",
	Short: "self-check",
	Run: func(cmd *cobra.Command, args []string) {
		// 配置检查
		{
			vp := viper.New()
			vp.AddConfigPath("./etc")
			vp.AddConfigPath("../etc")
			vp.SetConfigName("app")
			vp.SetConfigType("yaml")
			if err := vp.ReadInConfig(); err != nil {
				log.Fatal("解析配置文件出错 🔊 ", err)
			}
			if err := vp.Unmarshal(&config.Config); err != nil {
				log.Fatal("初始化配置出错 🔊 ", err)
			} else {
				log.Println("配置文件OK 🎉 ")
			}
		}
	},
}
